# -*- coding: utf-8 -*-
# בש״ד
#
# Miraflores Blog for Django - Part of the Cuba Libre Project
# Copyright (C) 2009, Joshua "jag" Ginsberg <jag@flowtheory.net>
# 
# Por mi amor, que inspira a mi cada respiración y que echa de Cuba
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from taino.api import Component
from teniente.api import ITemplateSlot, ITemplateSlotToken

class SharingOptions(Component):
    component_id = 'net.skwx.cubalibre.miraflores.SharingOptions'
    component_description = 'Blog entry sharing options'
    implements = [ITemplateSlot,]
    
    def wrap_token(self, token_html):
        return u'<span class="sharing-option">%s</span>' % token_html
    
    def render_slot(self, token_list):
        return u'<div class="sharing-options">%s</div>' % u'\n'.join(token_list)

class ShareOnReddit(Component):
    component_id = 'net.skwx.cubalibre.miraflores.ShareOnReddit'
    component_description = 'Share on Reddit'
    implements = [ITemplateSlotToken,]
    
    def get_slot_id(self):
        return 'net.skwx.cubalibre.miraflores.SharingOptions'
    
    def render_token(self, context):
        return u'''<a href="http://www.reddit.com/submit" onclick="window.location = 'http://www.reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://www.reddit.com/static/spreddit1.gif" alt="submit to reddit" border="0" /> </a>'''

class ShareOnDigg(Component):
    component_id = 'net.skwx.cubalibre.miraflores.ShareOnDigg'
    component_description = 'Share on Digg'
    implements = [ITemplateSlotToken,]
    
    def get_slot_id(self):
        return 'net.skwx.cubalibre.miraflores.SharingOptions'
    
    def render_token(self, context):
        return u'<script type="text/javascript">digg_skin = "icon";</script><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>'

class ShareOnFacebook(Component):
    component_id = 'net.skwx.cubalibre.miraflores.ShareOnFacebook'
    component_description = 'Share on Facebook'
    implements = [ITemplateSlotToken,]
    
    def get_slot_id(self):
        return 'net.skwx.cubalibre.miraflores.SharingOptions'
    
    def render_token(self, context):
        # return u'''<script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_button { display: -moz-inline-block; display:inline-block; padding:1px 20px 0 5px; height:15px; border:1px solid #d8dfea; background:url(http://b.static.ak.fbcdn.net/rsrc.php/zAB5S/hash/4273uaqa.gif) no-repeat top right; } html .fb_share_button:hover { color:#fff; border-color:#295582; background:#3b5998 url(http://b.static.ak.fbcdn.net/rsrc.php/zAB5S/hash/4273uaqa.gif) no-repeat top right; text-decoration:none; } </style> <a href="http://www.facebook.com/share.php?u=%s" class="fb_share_button" onclick="return fbs_click()" target="_blank" style="text-decoration:none;">Share</a>''' % current_url
        return u'''<a href="http://www.facebook.com/share.php" onClick="window.location = 'http://www.facebook.com/share.php?u=' + encodeURIComponent(window.location) + '&t=' + encodeURIComponent(document.title); return false"> <img src="http://b.static.ak.fbcdn.net/rsrc.php/zAB5S/hash/4273uaqa.gif" alt="Share on Facebook" border="0" /></a>'''


class ShareOnTwitter(Component):
    component_id = 'net.skwx.cubalibre.miraflores.ShareOnTwitter'
    component_description = 'Share on Twitter'
    implements = [ITemplateSlotToken,]
    
    def get_slot_id(self):
        return 'net.skwx.cubalibre.miraflores.SharingOptions'
    
    def render_token(self, context):
        return u'''<a href="http://twitter.com/home" onClick="window.location = 'http://twitter.com/home?status=From+' + encodeURIComponent(window.location); return false" title="Click to send this page to Twitter!" target="_blank"><img src="%simg/twitter.jpg" alt="Share on Twitter" /></a>''' % (context['MEDIA_URL'],)
